# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=innoextract
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=1.9
pkgver=1.9.r82.6e9e34e
pkgrel=1
_commit=6e9e34ed0876014fdb46e684103ef8c3605e382e
pkgdesc="A tool to extract installers created by Inno Setup (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://constexpr.org/innoextract/"
msys2_repository_url="https://github.com/dscharrer/innoextract"
license=("spdx:MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-python"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost-libs"
         "${MINGW_PACKAGE_PREFIX}-xz")
source=("git+https://github.com/dscharrer/innoextract#commit=${_commit}")
sha256sums=('9e12fe63358bfa1b9ed4810f850d2e628ef7b87acc1ad44fc4d35e1b3a8e2a8e')
validpgpkeys=("ADE9653703D4ADE0E997758128555A66D7E1DEC9") # Daniel Scharrer <daniel@constexpr.org>

pkgver() {
  cd ${_realname}
  printf "${_pkgver}.r%s.%s" "$(git rev-list --count ${_pkgver}..HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${_extra_config[@]}" \
    -DUSE_STATIC_LIBS=OFF \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    ../${_realname}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./

  install -Dm644 "${srcdir}"/${_realname}/README.md \
    "${pkgdir}"${MINGW_PREFIX}/share/doc/${_realname}/README.md
  install -Dm644 "${srcdir}"/${_realname}/CHANGELOG \
    "${pkgdir}"${MINGW_PREFIX}/share/doc/${_realname}/CHANGELOG
  install -Dm644 "${srcdir}"/${_realname}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
